var Background = pc.createScript('background');

Background.prototype.initialize = function () {
    this.background = this.addElement(this.entity, 'background', 'background', 0, 7, 0);
    this.background.rotateLocal(0, 0, -90);
    var scale = 0.011;
    this.background.setLocalScale(scale, scale, scale);
    console.log(this.background);
};

Background.prototype.addElement = function (_entity, name, assetName, x, y, z) {
    var entity = new pc.Entity(name);
    _entity.addChild(entity);
    var asset = assets.get(assetName);
    entity.addComponent('element', {
        type: "image",
        anchor: new pc.Vec4(0.5, 0.5, 0.5, 0.5),
        pivot: new pc.Vec2(0.5, 0.5),
        width: asset.resource.width,
        height: asset.resource.height,
        textureAsset: asset
    });
    this.makeImageToWorldLayer(entity);
    if (x == undefined)
        x = 0;
    if (y == undefined)
        y = 0;
    if (z == undefined)
        z = 0;
    entity.setLocalPosition(x, y, entity.getLocalPosition().z + z);
    return entity;
};

Background.prototype.makeImageToWorldLayer = function (entity) {
    if (entity && entity.element)
        entity.element.layers = [0];
};